package cc.rengu.igas.share.facade.bean.cups;

import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;

import java.util.Arrays;

/**
 * 域 125  QP用法子域TAG
 *
 * @author fangminwei
 * @date 2021/4/17
 */
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum F125_QP_SubTagEnum {
    _01("01", "cloudFlashPayBusiness", 3, "云闪付业务标志"),
    ;

    /**
     * 银联125域QR用法子域TAG名
     */
    private String cupsTagName;
    /**
     * 银联125域QR用法子域TAG名--》内部名称
     */
    private String innerTagName;
    /**
     * 银联125域QR用法子域TAG 值长度
     */
    private int length;
    /**
     * 描述
     */
    private String desc;

    F125_QP_SubTagEnum(String cupsTagName, String innerTagName, int length, String desc) {
        this.cupsTagName = cupsTagName;
        this.innerTagName = innerTagName;
        this.length = length;
        this.desc = desc;
    }

    public String getCupsTagName() {
        return cupsTagName;
    }

    public String getInnerTagName() {
        return innerTagName;
    }

    public int getLength() {
        return length;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return cupsTagName + "-" + innerTagName + "-" + desc;
    }

    /**
     * 通过内部tag名称获取枚举
     *
     * @param innerTagName 内部tag名称
     * @return 125域子域TAG的枚举
     */
    public static F125_QP_SubTagEnum findByInnerTagName(String innerTagName) {
        F125_QP_SubTagEnum result = Arrays.stream(F125_QP_SubTagEnum.values())
                .filter(e -> e.getInnerTagName().equals(innerTagName)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + innerTagName);
        }
        return result;
    }

    /**
     * 通过银联tag名称获取枚举
     *
     * @param cupsTagName 银联tag名称
     * @return 125域子域TAG的枚举
     */
    public static F125_QP_SubTagEnum findByCupsTagName(String cupsTagName) {
        F125_QP_SubTagEnum result = Arrays.stream(F125_QP_SubTagEnum.values())
                .filter(e -> e.getCupsTagName().equals(cupsTagName)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + cupsTagName);
        }
        return result;
    }
}
